<!DOCTYPE html>
<html lang="en-us">
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
<meta charset="UTF-8">
<title>Tune for indexing speed | Elasticsearch Guide [7.7] | Elastic</title>
<link rel="home" href="index.html" title="Elasticsearch Guide [7.7]">
<link rel="up" href="how-to.html" title="How To">
<link rel="prev" href="static-scoring-signals.html" title="Incorporating static relevance signals into the score">
<link rel="next" href="tune-for-search-speed.html" title="Tune for search speed">
<meta name="DC.type" content="Learn/Docs/Elasticsearch/Reference/7.7">
<meta name="DC.subject" content="Elasticsearch">
<meta name="DC.identifier" content="7.7">
<meta name="robots" content="noindex,nofollow">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.optimizely.com/js/18132920325.js"></script>
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/manifest.json">
    <meta name="apple-mobile-web-app-title" content="Elastic">
    <meta name="application-name" content="Elastic">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/mstile-144x144.png">
    <meta name="theme-color" content="#ffffff">
    <meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd">
    <meta name="yandex-verification" content="d8a47e95d0972434">
    <meta name="localized" content="true">
    <meta name="st:robots" content="follow,index">
    <meta property="og:image" content="https://www.elastic.co/static/images/elastic-logo-200.png">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
    <link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
    <link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/guide/static/styles.css">
  </head>

  <!--© 2015-2021 Elasticsearch B.V. Copying, publishing and/or distributing without written permission is strictly prohibited.-->

  <body>
    <!-- Google Tag Manager -->
    <script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
    <!-- End Google Tag Manager -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-12395217-16');
    </script>

    <!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->
    <script type="text/javascript">
      (function(){var g=function(e,h,f,g){
      this.get=function(a){for(var a=a+"=",c=document.cookie.split(";"),b=0,e=c.length;b<e;b++){for(var d=c[b];" "==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};
      this.set=function(a,c){var b="",b=new Date;b.setTime(b.getTime()+6048E5);b="; expires="+b.toGMTString();document.cookie=a+"="+c+b+"; path=/; "};
      this.check=function(){var a=this.get(f);if(a)a=a.split(":");else if(100!=e)"v"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(":"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case "v":return!1;case "r":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(":")),!c}return!0};
      this.go=function(){if(this.check()){var a=document.createElement("script");a.type="text/javascript";a.src=g;document.body&&document.body.appendChild(a)}};
      this.start=function(){var a=this;window.addEventListener?window.addEventListener("load",function(){a.go()},!1):window.attachEvent&&window.attachEvent("onload",function(){a.go()})}};
      try{(new g(100,"r","QSI_S_ZN_emkP0oSe9Qrn7kF","https://znemkp0ose9qrn7kf-elastic.siteintercept.qualtrics.com/WRSiteInterceptEngine/?Q_ZID=ZN_emkP0oSe9Qrn7kF")).start()}catch(i){}})();
    </script><div id="ZN_emkP0oSe9Qrn7kF"><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>
    <!--END WEBSITE FEEDBACK SNIPPET-->

    <div id="elastic-nav" style="display:none;"></div>
    <script src="https://www.elastic.co/elastic-nav.js"></script>

    <!-- Subnav -->
    <div>
      <div>
        <div class="tertiary-nav d-none d-md-block">
          <div class="container">
            <div class="p-t-b-15 d-flex justify-content-between nav-container">
              <div class="breadcrum-wrapper"><span><a href="/guide/" style="font-size: 14px; font-weight: 600; color: #000;">Docs</a></span></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="main-container">
      <section id="content">
        <div class="content-wrapper">

          <section id="guide" lang="en">
            <div class="container">
              <div class="row">
                <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                  <!-- start body -->
                  <div class="page_header">
<strong>IMPORTANT</strong>: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
<a href="../current/index.html">current release documentation</a>.
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="how-to.html">How To</a></span>
»
<span class="breadcrumb-node">Tune for indexing speed</span>
</div>
<div class="navheader">
<span class="prev">
<a href="static-scoring-signals.html">« Incorporating static relevance signals into the score</a>
</span>
<span class="next">
<a href="tune-for-search-speed.html">Tune for search speed »</a>
</span>
</div>
<div class="chapter">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="tune-for-indexing-speed"></a>Tune for indexing speed<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h2>
</div></div></div>
<h3>
<a id="_use_bulk_requests"></a>Use bulk requests<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>Bulk requests will yield much better performance than single-document index
requests. In order to know the optimal size of a bulk request, you should run
a benchmark on a single node with a single shard. First try to index 100
documents at once, then 200, then 400, etc. doubling the number of documents
in a bulk request in every benchmark run. When the indexing speed starts to
plateau then you know you reached the optimal size of a bulk request for your
data. In case of tie, it is better to err in the direction of too few rather
than too many documents. Beware that too large bulk requests might put the
cluster under memory pressure when many of them are sent concurrently, so
it is advisable to avoid going beyond a couple tens of megabytes per request
even if larger requests seem to perform better.</p>
<h3>
<a id="multiple-workers-threads"></a>Use multiple workers/threads to send data to Elasticsearch<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>A single thread sending bulk requests is unlikely to be able to max out the
indexing capacity of an Elasticsearch cluster. In order to use all resources
of the cluster, you should send data from multiple threads or processes. In
addition to making better use of the resources of the cluster, this should
help reduce the cost of each fsync.</p>
<p>Make sure to watch for <code class="literal">TOO_MANY_REQUESTS (429)</code> response codes
(<code class="literal">EsRejectedExecutionException</code> with the Java client), which is the way that
Elasticsearch tells you that it cannot keep up with the current indexing rate.
When it happens, you should pause indexing a bit before trying again, ideally
with randomized exponential backoff.</p>
<p>Similarly to sizing bulk requests, only testing can tell what the optimal
number of workers is. This can be tested by progressively increasing the
number of workers until either I/O or CPU is saturated on the cluster.</p>
<h3>
<a id="_unset_or_increase_the_refresh_interval"></a>Unset or increase the refresh interval<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>The operation that consists of making changes visible to search - called a
<a class="xref" href="indices-refresh.html" title="Refresh API">refresh</a> - is costly, and calling it often while there is
ongoing indexing activity can hurt indexing speed.</p>
<p>By default, Elasticsearch periodically refreshes indices every second, but only on
indices that have received one search request or more in the last 30 seconds.</p>
<p>This is the optimal configuration if you have no or very little search traffic
(e.g. less than one search request every 5 minutes) and want to optimize for
indexing speed. This behavior aims to automatically optimize bulk indexing in
the default case when no searches are performed. In order to opt out of this
behavior set the refresh interval explicitly.</p>
<p>On the other hand, if your index experiences regular search requests, this
default behavior means that Elasticsearch will refresh your index every 1
second. If you can afford to increase the amount of time between when a document
gets indexed and when it becomes visible, increasing the
<a class="xref" href="index-modules.html#index-refresh-interval-setting"><code class="literal">index.refresh_interval</code></a> to a larger value, e.g.
<code class="literal">30s</code>, might help improve indexing speed.</p>
<h3>
<a id="_disable_replicas_for_initial_loads"></a>Disable replicas for initial loads<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>If you have a large amount of data that you want to load all at once into
Elasticsearch, it may be beneficial to set <code class="literal">index.number_of_replicas</code> to <code class="literal">0</code> in
order to speep up indexing. Having no replicas means that losing a single node
may incur data loss, so it is important that the data lives elsewhere so that
this initial load can be retried in case of an issue. Once the initial load is
finished, you can set <code class="literal">index.number_of_replicas</code> back to its original value.</p>
<p>If <code class="literal">index.refresh_interval</code> is configured in the index settings, it may further
help to unset it during this initial load and setting it back to its original
value once the initial load is finished.</p>
<h3>
<a id="_disable_swapping_2"></a>Disable swapping<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>You should make sure that the operating system is not swapping out the java
process by <a class="xref" href="setup-configuration-memory.html" title="Disable swapping">disabling swapping</a>.</p>
<h3>
<a id="_give_memory_to_the_filesystem_cache"></a>Give memory to the filesystem cache<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>The filesystem cache will be used in order to buffer I/O operations. You should
make sure to give at least half the memory of the machine running Elasticsearch
to the filesystem cache.</p>
<h3>
<a id="_use_auto_generated_ids"></a>Use auto-generated ids<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>When indexing a document that has an explicit id, Elasticsearch needs to check
whether a document with the same id already exists within the same shard, which
is a costly operation and gets even more costly as the index grows. By using
auto-generated ids, Elasticsearch can skip this check, which makes indexing
faster.</p>
<h3>
<a id="_use_faster_hardware"></a>Use faster hardware<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>If indexing is I/O bound, you should investigate giving more memory to the
filesystem cache (see above) or buying faster drives. In particular SSD drives
are known to perform better than spinning disks. Always use local storage,
remote filesystems such as <code class="literal">NFS</code> or <code class="literal">SMB</code> should be avoided. Also beware of
virtualized storage such as Amazon’s <code class="literal">Elastic Block Storage</code>. Virtualized
storage works very well with Elasticsearch, and it is appealing since it is so
fast and simple to set up, but it is also unfortunately inherently slower on an
ongoing basis when compared to dedicated local storage. If you put an index on
<code class="literal">EBS</code>, be sure to use provisioned IOPS otherwise operations could be quickly
throttled.</p>
<p>Stripe your index across multiple SSDs by configuring a RAID 0 array. Remember
that it will increase the risk of failure since the failure of any one SSD
destroys the index. However this is typically the right tradeoff to make:
optimize single shards for maximum performance, and then add replicas across
different nodes so there’s redundancy for any node failures. You can also use
<a class="xref" href="modules-snapshots.html" title="Snapshot module">snapshot and restore</a> to backup the index for further
insurance.</p>
<h3>
<a id="_indexing_buffer_size"></a>Indexing buffer size<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>If your node is doing only heavy indexing, be sure
<a class="xref" href="indexing-buffer.html" title="Indexing buffer settings"><code class="literal">indices.memory.index_buffer_size</code></a> is large enough to give
at most 512 MB indexing buffer per shard doing heavy indexing (beyond that
indexing performance does not typically improve). Elasticsearch takes that
setting (a percentage of the java heap or an absolute byte-size), and
uses it as a shared buffer across all active shards. Very active shards will
naturally use this buffer more than shards that are performing lightweight
indexing.</p>
<p>The default is <code class="literal">10%</code> which is often plenty: for example, if you give the JVM
10GB of memory, it will give 1GB to the index buffer, which is enough to host
two shards that are heavily indexing.</p>
<h3>
<a id="_use_cross_cluster_replication_to_prevent_searching_from_stealing_resources_from_indexing"></a>Use cross-cluster replication to prevent searching from stealing resources from indexing<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>Within a single cluster, indexing and searching can compete for resources. By
setting up two clusters, configuring <a class="xref" href="xpack-ccr.html" title="Cross-cluster replication">cross-cluster replication</a> to replicate data from
one cluster to the other one, and routing all searches to the cluster that has
the follower indices, search activity will no longer steal resources from
indexing on the cluster that hosts the leader indices.</p>
<h3>
<a id="_additional_optimizations"></a>Additional optimizations<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/how-to/indexing-speed.asciidoc">edit</a>
</h3>
<p>Many of the strategies outlined in <a class="xref" href="tune-for-disk-usage.html" title="Tune for disk usage"><em>Tune for disk usage</em></a> also
provide an improvement in the speed of indexing.</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="static-scoring-signals.html">« Incorporating static relevance signals into the score</a>
</span>
<span class="next">
<a href="tune-for-search-speed.html">Tune for search speed »</a>
</span>
</div>
</div>

                  <!-- end body -->
                </div>
                <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                  <div id="rtpcontainer" style="display: block;">
                    <div class="mktg-promo">
                      <h3>Most Popular</h3>
                      <ul class="icons">
                        <li class="icon-elasticsearch-white"><a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&amp;elektra=docs&amp;storm=top-video">Get Started with Elasticsearch: Video</a></li>
                        <li class="icon-kibana-white"><a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&amp;elektra=docs&amp;storm=top-video">Intro to Kibana: Video</a></li>
                        <li class="icon-logstash-white"><a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&amp;elektra=docs&amp;storm=top-video">ELK for Logs &amp; Metrics: Video</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </section>

        </div>


<div id="elastic-footer"></div>
<script src="https://www.elastic.co/elastic-footer.js"></script>
<!-- Footer Section end-->

      </section>
    </div>

<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs.js"></script>
<script type="text/javascript">
  window.initial_state = {}</script>
  </body>
</html>
